﻿using Styx.Common;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

namespace TuanHA_Paladin
{
    public partial class Classname
    {
        #region Protection Rotation

        private Composite ProtectionRotation()
        {
            return new PrioritySelector(
                new Action(delegate
                               {
                                   if (THSettings.Instance.SAutoTarget && !Me.Mounted &&
                                       Me.CurrentTarget != null && UnitAttack != null &&
                                       Me.CurrentTarget != UnitAttack &&
                                       UnitAttack.Combat && //Make sure don't aggro more
                                       (Me.CurrentTarget.Distance - 5 > UnitAttack.Distance ||
                                        !Me.CurrentTarget.InLineOfSpellSight ||
                                        !Me.CurrentTarget.IsAlive ||
                                        !Me.CurrentTarget.Combat && Me.Combat))
                                   {
                                       Logging.Write(LogLevel.Diagnostic, "Select new Target");
                                       UnitAttack.Target();
                                   }

                                   //target the lowest threat unit
                                   if (THSettings.Instance.SAutoTarget && Me.CurrentTarget != null &&
                                       Me.CurrentTarget.IsValid && GetUnitLowThreat() &&
                                       _unitLowThreat.IsValid && Me.CurrentTarget != _unitLowThreat &&
                                       Me.CurrentTarget.ThreatInfo.RawPercent > _unitLowThreat.ThreatInfo.RawPercent + 5)
                                   {
                                       _unitLowThreat.Target();
                                       Logging.Write(LogLevel.Diagnostic, "Switch to Lowest Threat Target");
                                   }

                                   //target the lowest threat unit
                                   if (THSettings.Instance.SAutoTarget && Me.CurrentTarget == null &&
                                       GetUnitLowThreat() &&
                                       _unitLowThreat.IsValid)
                                   {
                                       _unitLowThreat.Target();
                                       Logging.Write(LogLevel.Diagnostic, "Target  Lowest Threat Unit");
                                   }

                                   //Hold dps on Dungeon or Raid in No Combat
                                   if ((Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) &&
                                       !Me.Combat)
                                   {
                                       return RunStatus.Success;
                                   }

                                   ////Hold dps on Dungeon 
                                   //if (Me.CurrentMap.IsDungeon &&
                                   //    Me.CurrentTarget != null &&
                                   //    !Me.CurrentTarget.IsTargetingMyPartyMember)
                                   //{
                                   //    return RunStatus.Success;
                                   //}

                                   ////Hold dps on Dungeon or Raid
                                   //if (Me.CurrentMap.IsRaid &&
                                   //    Me.CurrentTarget != null &&
                                   //    Me.CurrentTarget.IsTargetingMyRaidMember)
                                   //{
                                   //    return RunStatus.Success;
                                   //}


                                   return RunStatus.Failure;
                               }),
                ////Trying to stop bot movement while casting
                //new Decorator(
                //    ret =>
                //    Me.IsCasting,
                //    new Action(delegate { return RunStatus.Success; })
                //    ),
                //But first, facing target
                new Decorator(
                    ret =>
                    THSettings.Instance.SFace &&
                    ValidUnit(Me.CurrentTarget) &&
                    IsEnemy(Me.CurrentTarget) &&
                    !Me.IsFacing(Me.CurrentTarget) &&
                    Me.CurrentTarget.InLineOfSpellSight &&
                    !IsOverrideModeOn,
                    new Action(delegate
                                   {
                                       Me.CurrentTarget.Face();
                                       return RunStatus.Failure;
                                   })
                    ),
                ReckoningCompProtection(),
                ArdentDefender(),
                BubbleFlashofLightRet(),
                CancelBubbleProtection(),
                //Starting the movement right here
                //MovementMoveBehind(ret => Me.CurrentTarget),
                MovementMoveToMelee(ret => Me.CurrentTarget),
                MovementMoveStop(ret => Me.CurrentTarget, 3),
                //DPS Rotation Here
                SetAutoAttack(),
                LayonHandsMe(),
                Rebuke(),
                ArcaneTorrent(),
                AvengingWrathBurstRet(),
                HolyAvengerBurstRet(),
                DivineProtectionMe(),
                DevotionAura(),
                UseHealthstone(),
                UseBattleStandard(),
                GuardianofAncientKingsProtection(),
                AvengersShieldInterrupt(),
                HammerofJustice(),
                BlindingLight(),
                WarStomp(),
                DivineShieldMe(),
                HandofProtectionMe(),
                SacredShieldMeProt(),
                HandofProtectionFriendRemoveCC(),
                HandofProtectionFriend(),
                CrowdControlSurviveComp(),
                HandofFreedomMe(),
                SealProtection(),
                AvengersShieldLoseThreat(),
                FlashofLightSelflessHealer(),
                WordofGloryMeProtection(),
                ShieldoftheRighteous(),
                AvengersShieldGrandCrusader(),
                JudgementRangeRetPvP(),
                HammeroftheRighteousProtection(),
                CrusaderStrikeRet(),
                JudgementRet(),
                AvengersShieldLowestThreatUnit(),
                AvengersShield(),
                HammerofWrathCurrentTarget(),
                HammerofWrathUnitHammerofWrath(),
                HolyPrismRet(),
                HolyPrismHeal(),
                ExecutionSentenceRet(),
                ExecutionSentenceHeal(),
                LightHammerRet(),
                LightHammerHeal(),
                Consecration(),
                ConsecrationGlyph(),
                HolyWrath(),
                WordofGloryMeTopUpRet(),
                FlashofLightMeRet(),
                FlashofLightFriendRet(),
                FlashofLightMeTopUpRet(),
                BuffRotation(),
                RighteousFury(),
                WriteDebug("")
                );
        }

        #endregion
    }
}